package
{
	import flash.display.Bitmap;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.Rectangle;
	
	import nl.sanity.ui.Button;
	import nl.sanity.ui.CheckBox;
	import nl.sanity.ui.Label;
	import nl.sanity.ui.RadioButton;
	import nl.sanity.ui.helpers.LabelStyle;
	
	[SWF(width='800', height='600', backgroundColor='#ffffff', framerate='25')]
	
	public class UIComponentExample extends Sprite
	{
		[Embed( source="MyriadPro-Semibold.ttf", fontName="MyriadPro", mimeType="application/x-font")]
		private var MyriadPro:Class;
		
		[Embed( source="button_default.png" ) ]
		public var DefaultButtonMap:Class;
		
		[Embed( source="radiobutton_default.png" ) ]
		public var DefaultRadioButtonMap:Class;
		
		[Embed( source="checkbox_default.png" ) ]
		public var DefaultCheckBoxMap:Class;
		
		public function UIComponentExample()
		{
			stage ? init() : addEventListener( Event.ADDED_TO_STAGE, init );
		}
		
		private function init( event:Event = null ):void
		{
			removeEventListener( Event.ADDED_TO_STAGE, init );
			
			var button:Button;
			var checkbox:CheckBox;
			var radioButton:RadioButton;
			
			/*
			-------< BUTTONS >-------- 
			*/
			
			// Button
			var labelStyle:LabelStyle	= new LabelStyle();
			labelStyle.setAllStyles( { fontFamily: "MyriadPro", color: "#FFFFFF", fontSize: 14 } );
			labelStyle.setStyle( LabelStyle.CSS_UP, { fontFamily: "MyriadPro", color: "#27333a", fontSize: 14 } );
			labelStyle.setStyle( LabelStyle.CSS_OVER, { fontFamily: "MyriadPro", color: "#FFFFFF", fontSize: 14 } );
			labelStyle.setStyle( LabelStyle.CSS_DOWN, { fontFamily: "MyriadPro", color: "#FFFFFF", fontSize: 14 } );
			labelStyle.setStyle( LabelStyle.CSS_DISABLED, { fontFamily: "MyriadPro", color: "#999999", fontSize: 14 } );
			
			button				= new Button( this, 50, 50 );
			button.label		= "Button Label";
			button.labelStyle	= labelStyle;
			button.enabled		= true;
			button.width		= 200;
			button.height		= 32;
			button.setStateMap( new DefaultButtonMap(), new Rectangle( 10, 10, 108, 12 ), true );
			
			// Disabled Button
			button				= new Button( this, 400, 50 );
			button.label		= "Button Label";
			button.labelStyle	= labelStyle;
			button.enabled		= false;
			button.width		= 200;
			button.height		= 32;
			button.setStateMap( new DefaultButtonMap(), new Rectangle( 10, 10, 108, 12 ), true );
			
			
			/*
			-------< RADIOBUTTONS >-------- 
			*/
			
			// Style definition
			labelStyle	= new LabelStyle();
			labelStyle.setAllStyles( { fontFamily: "MyriadPro", color: "#27333a", fontSize: 14 } );
			labelStyle.setStyle( LabelStyle.CSS_DISABLED, { fontFamily: "MyriadPro", color: "#999999", fontSize: 14 } );
			
			// RadioButton 1
			radioButton				= new RadioButton( this, 50, 150, "group1" );
			radioButton.label		= "This is radiobutton 1";
			radioButton.labelStyle	= labelStyle;
			radioButton.selected	= true;
			radioButton.setStateMap( new DefaultRadioButtonMap() );
			
			// RadioButton 2
			radioButton				= new RadioButton( this, 50, 180, "group1" );
			radioButton.label		= "This is radiobutton 2";
			radioButton.labelStyle	= labelStyle;
			radioButton.setStateMap( new DefaultRadioButtonMap() );
			
			// Disabled RadioButton 1
			radioButton				= new RadioButton( this, 400, 150 );
			radioButton.label		= "This is radiobutton 1";
			radioButton.labelStyle	= labelStyle;
			radioButton.selected	= true;
			radioButton.enabled		= false;
			radioButton.setStateMap( new DefaultRadioButtonMap() );
			
			// Disabled RadioButton 2
			radioButton				= new RadioButton( this, 400, 180 );
			radioButton.label		= "This is radiobutton 2";
			radioButton.labelStyle	= labelStyle;
			radioButton.enabled		= false;
			radioButton.setStateMap( new DefaultRadioButtonMap() );
			
			/*
			-------< CHECKBOXES >-------- 
			*/
			
			// CheckBox
			checkbox				= new CheckBox( this, 50, 250 );
			checkbox.label			= "This is a checkbox example";
			checkbox.labelStyle		= labelStyle;
			checkbox.scalable		= false;
			checkbox.setStateMap( new DefaultCheckBoxMap() );
			
			// Disabled CheckBox
			checkbox				= new CheckBox( this, 400, 250 );
			checkbox.label			= "This is a checkbox example";
			checkbox.labelStyle		= labelStyle;
			checkbox.enabled		= false;
			checkbox.setStateMap( new DefaultCheckBoxMap() );
			
			/*
			-------< USED IMAGEMAPS >-------- 
			*/
			
			var image:Bitmap;
		
			image	= new DefaultButtonMap();
			image.x	= 50;
			image.y	= 350;
			addChild( image );
			
			image	= new DefaultRadioButtonMap();
			image.x	= 250;
			image.y	= 350;
			addChild( image );
			
			image	= new DefaultCheckBoxMap();
			image.x	= 350;
			image.y	= 350;
			addChild( image );

			/*
			// THIS ALSO WORKS OUT FOR SETTING A SINGLE STATE
			button.setState( DisplayState.UP, upState );
			button.setState( DisplayState.OVER, overState );
			button.setState( DisplayState.DOWN, downState );
			*/			
		}
	}
}
